//
//  HCRegisteredViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/22.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCRegisteredViewController.h"

#import "HCRegisteredView.h"

#import "HCRegisterSecondViewController.h"

@interface HCRegisteredViewController () <HCRegisterDelegate>

@property (nonatomic, copy) NSString *phoneNO;
@property (nonatomic, copy) NSString *codeString;
@property (nonatomic, strong) HCRegisteredView *registerView;

@end

@implementation HCRegisteredViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"注册";
    
    self.registerView = [[HCRegisteredView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    self.registerView.delegate = self;
    [self.centerView addSubview:self.registerView];
    
    self.dataRequest.delegate = self;
    
    
    // Do any additional setup after loading the view.
}

-(void)hc_registerGetCode:(NSString *)phone {
   
    [self.dataRequest postHC_RegisterCheck:phone];
    _phoneNO = [NSString stringWithFormat:@"%@",phone];
    HCUSERDEFUALTS(_phoneNO, @"to");
    HCUSERDEFUALTS(phone, @"userphone");
}

- (void)hc_registerValidateCode:(NSString *)code {

    NSLog(@"点击验证");
    if ([self.codeString isEqualToString:code]) {
        
        //验证成功
        HCRegisterSecondViewController *hcregisterSecondVC = [[HCRegisterSecondViewController alloc] init];
        [self.navigationController pushViewController:hcregisterSecondVC animated:YES];
    }
    else {
    
        //验证码不正确
        [XHToast showBottomWithText:@"验证码不正确"];
    }
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    NSLog(@"手机号码验证:%@",dictionary);
    
    if ([dictionary[@"stat"] integerValue] == 200) {
        
        //验证码发送成功
        self.codeString = [NSString stringWithFormat:@"%@",dictionary[@"param"]];
        [XHToast showBottomWithText:@"验证码发送成功"];
        [self.registerView startCountDown];
        
    }else{
        
        [XHToast showBottomWithText:@"此手机号码已经注册"];
    }
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"失败，验证手机号码");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
